import type { RequestInterceptors } from '../types'

export const userHandleResponse = (): RequestInterceptors => {
  return {
    responseInterceptor(config) {
      const res = config.data
      res.message = res.msg

      // 兼容MTable
      if (Array.isArray(res.rows)) {
        res.data = res.rows
        res.count = res.total
      }

      config.data = res

      return config
    }
  }
}
